package view;

import entity.CourseDO;
import entity.StudentDO;
import handler.AddCourseViewHandler;

import javax.swing.*;
import java.awt.*;

public class AddCourseView extends JDialog {
    JPanel jPanel = new JPanel();
    //    JLabel snoLabel = new JLabel("学号");
//    JTextField snoTxt = new JTextField();
    JLabel nameLabel = new JLabel("课程名");
    JTextField nameTxt = new JTextField();

    JLabel snoLabel = new JLabel("课程号");
    JTextField snoTxt = new JTextField();

    JLabel sexLabel = new JLabel("学分");
    JTextField sexTxt = new JTextField();

    JLabel ageLabel = new JLabel("教师号");
    JTextField ageTxt = new JTextField();


    //    JLabel deptLabel = new JLabel("系别");
//    JTextField deptTxt = new JTextField();
//
//
//    JLabel speLabel = new JLabel("专业");
//    JTextField speTxt = new JTextField();
//
//
//    JLabel sclass = new JLabel("班级");
//    JTextField classTxt = new JTextField();
//
    JButton addBtn = new JButton("添加");

    AddCourseViewHandler addCourseViewHandler;

    public AddCourseView(CourseView courseView) {
        super(courseView, "添加信息", true);

        addCourseViewHandler = new AddCourseViewHandler(this, courseView);

        snoLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(snoLabel);
        snoTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(snoTxt);

        nameLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(nameLabel);
        nameTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(nameTxt);


        sexLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(sexLabel);
        sexTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(sexTxt);

        ageLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(ageLabel);
        ageTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(ageTxt);
//
//        deptLabel.setPreferredSize(new Dimension(80,30));
//        jPanel.add(deptLabel);
//        deptTxt.setPreferredSize(new Dimension(200,30));
//        jPanel.add(deptTxt);
//
//        speLabel.setPreferredSize(new Dimension(80,30));
//        jPanel.add(speLabel);
//        speTxt.setPreferredSize(new Dimension(200,30));
//        jPanel.add(speTxt);
//
//        sclass.setPreferredSize(new Dimension(80,30));
//        jPanel.add(sclass);
//        classTxt.setPreferredSize(new Dimension(200,30));
//        jPanel.add(classTxt);
//
//
        addBtn.addActionListener(addCourseViewHandler);
//
        jPanel.add(addBtn);

        Container contenPane = getContentPane();
        contenPane.add(jPanel);

        setSize(600, 400);//大小
        setVisible(true);//可以看见
        setResizable(false);//不可变大小
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);//退出自动关闭
        setLocationRelativeTo(null);//居中
    }

    public CourseDO buildCourseDO() {
        CourseDO courseDO = new CourseDO();
        courseDO.setCno(Integer.valueOf(snoTxt.getText()));
        courseDO.setCname(nameTxt.getText());
        courseDO.setCredits(sexTxt.getText());
        courseDO.setTno(ageTxt.getText());

        return courseDO;
    }

}
